﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class GameManaer : MonoBehaviour {


    public static GameManaer instance;
    public bool isGameOver = false;

  

    public Text scoreText;
    public Text gameOverText;

    public int score;

    void Awake () {

        if (instance == null)
            // 如果没有自己这个脚本对象，将自身登录
            instance = this;
        //...otherwise...
        else if (instance != this)
            // 如果已经有这个脚本对象，销毁自己（保持唯一）
            Destroy (gameObject);
    }

    // Update is called once per frame
    void Update () {
        // 如果游戏结束并且点击了鼠标左键

        gameOverText.gameObject.SetActive(isGameOver);

        if (isGameOver && Input.GetMouseButtonDown (0)) {

            // 重载正在激活的的场景（也就是用来保存项目的Main.unity文件）
            // SceneManager.LoadScene (SceneManager.GetActiveScene ().buildIndex);
            SceneManager.LoadScene (0);
            isGameOver = false;
        }

        scoreText.text = "Score:" + score.ToString ();
    }
}